import React from "react";

import { isNull} from '../common';

import {UIDataTableView} from '../uicomponents/UIDataComponentView';


const WarpUIDataTablePage = (props) => {
    class WarpedUIDataTablePage extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                selectRowKeys: [],
                searchData: {},
                ...props.state,
            };
        }

        actionHandler = (actionEvent) => {
            
            const extActions = props.actionHandler !== undefined ? props.actionHandler(actionEvent, this) : {};

            return extActions;
        }

        render() {

            const objTableProps = {
                tableConfigId: props.tableConfigId,
                actionGroupId: props.actionGroupId,
                rowActionGroupId: props.rowActionGroupId,
                dataUrl: props.dataUrl,
                autoLoad: props.autoLoad,
                bordered: props.bordered,
                selectMode: props.selectMode,
                searchFormId: props.searchFormId,
                actionHandler: this.actionHandler,
                ref: (inst) => { this.objectListRef = inst },
                setToolbarState: (topToolBar, selectedIds) => {
                    
                    if (props.setToolbarState != null) {
                        props.setToolbarState(topToolBar, selectedIds);
                    }
                },
                onSelectChange:
                    (selectRowKeys) => {
                        this.selectObjectIds = selectRowKeys;
                        this.setState({ selectObjectIds: selectRowKeys });
                    }
                ,
            };

            return (
                <UIDataTableView  {...objTableProps}>
                    {isNull(props.children) !== true ? props.children(this) : null}
                </UIDataTableView>
            );
        }
    }

    return WarpedUIDataTablePage;
}

export default WarpUIDataTablePage;